#VERSION    =1.20
CC         =g++
FILETYPE   =cpp
TARGET     =main
SRC    =chess_pieces.cpp communication.cpp service.cpp
# 共享文件目录 .o的目录
SHAREDIR=
# .o文件
shareFile=
#SRC    =$(wildcard *.$(FILETYPE))
DEBUG      =-g
STD        =-std=c11
CFLAGS     =-Wall
INCLUDES   =-I./
# -lmylib 对应库文件是 (libmylib.a) 或者(libmylib.so)
LIB_NAMES  =
# -L./lib
LIB_PATH   =
OUTDIR     :=./build/
OBJ         =$(patsubst %.$(FILETYPE),%.o, $(SRC))
RELY_C =.rely_c

vpath %.o $(OUTDIR) $(SHAREDIR)

.PHONY:all
all:$(OUTDIR)$(TARGET) $(RELY_C)

$(RELY_C):
	@if [ ! -e $(OUTDIR) ];then  mkdir -p ./$(OUTDIR);fi
	@for i in *.$(FILETYPE);do gcc -MM $$i ;done > $(RELY_C)

create_dir:
	@if [ ! -e $(OUTDIR) ];then  mkdir -p ./$(OUTDIR);fi

#links
$(OUTDIR)$(TARGET):$(OBJ) $(shareFile)
	@echo -e "\033[32m $(CC) $^ $(LIB_PATH) $(LIB_NAMES) -o $@ \033[0m"
	@$(CC) $^ $(LIB_PATH) $(LIB_NAMES) -o $@
	@echo -e "\033[1;32m create $@ succeed\033[0m"
	@mv *.o $(OUTDIR)

#compile
%.o:%.$(FILETYPE)
	$(CC) $(INCLUDES) $(DEBUG) -c $(CFLAGS) $< -o $@

.PHONY:run
run:
	./$(OUTDIR)/$(TARGET) 

.PHONY:clean
clean:
	@echo "Remove linked and compiled files......"
	rm -rf $(OUTDIR) $(RELY_C) ./*.o

include $(RELY_C)
